/*
 * @Description: 触发消息列表配置
 * @version: 电子名片2.0
 * @Author: 尹鑫
 * @Date: 2020-12-04 11:33:08
 * @LastEditors: 尹鑫
 * @LastEditTime: 2020-12-16 10:55:46
 */
function transformParams(editList, detail, isRed) {
  editList.forEach(item => {
    if (item.transform) {
      item.transform(detail);
    } else {
      item.value = detail[item.key]
    }
    if (isRed && !item.disabled) item.disabled = true;
  })
}
export function configData(detail) {
  const listHedar = [
    { prop: 'id', label: '短信消息编号' },
    { prop: 'notifyTitle', label: '短信标题' },
    { prop: 'tempName', label: '短信模板'},
    { prop: 'smsSign', label: '短信签名' },
    {
      prop: 'sendStatus', label: '发送状态',
      show: { '0': '未发送', '1': '发送成功', '2': '发送失败', default: '未发送' }
    },
    { prop: 'sendTime', label: '发送时间' },
    { prop: 'modifierName', label: '修改人' },
    { prop: 'gmtModified', label: '修改时间' },
    { prop: 'operate', label: '操作', isTemplate: true }
  ]
  const searchs = [
    { type: 'input', key: 'keyword', value: '', placeholder: '短信消息编号' },
    {
      type: 'select', key: 'sendStatus', value: '', placeholder: '状态',
      selectList: [
        { value: '0', title: '未发送' },
        { value: '1', title: '发送成功' },
        { value: '2', title: '发送失败' }
      ]
    }
  ]
  return {
    listHedar, searchs
  }
}
export function createEditData(detail, list, isRed, tagList) {
  let editList = [];
  if (isRed) {
    editList = [
      { type: 'input', key: 'notifyTitle', label: '短信标题：', value: '', have: true },
      { type: 'input', key: 'sendTime', label: '发送时间：', value: '', have: true },
      {
        type: 'select', key: 'smsId', label: '短信模板：', value: '', have: true,
        options: list,
        change(value = this.value) {
          const _select = list.find(item => item.value === value);
          if (!_select) return;
          editList.find(item => item.key === 'notifyTemContent').value = _select.content;
        }
      },
      { type: 'textarea', key: 'notifyTemContent', label: '模板内容：', value: '', disabled: true, have: true, notParams: true }
    ]
  } else {
    editList = [
      { type: 'input', key: 'notifyTitle', label: '短信标题：', value: '', have: true },
      { 
        type: 'select', key: 'tagId', label: '接收对象：', value: '', have: true,
        options: tagList
      },
      {
        type: 'radio', key: 'sendType', label: '发送时间：', value: 0, have: true,
        data: [
          { value: 0, title: '立即发送' },
          { value: 1, title: '定时发送', date: { value: ''} }
        ],
        transform(detail) {
          this.value = detail.sendType;
          this.data.find(item => item.value === 1).date.value = detail.sendTime;
        },
        setParams() {
          const _params = { sendType: this.value };
          if (this.value == 1) {
            const _date = this.data.find(item => item.value === 1).date.value;
            if (!_date) return null;
            _params.sendTime = _date;
          }
          return _params;
        }
      },
      {
        type: 'select', key: 'smsId', label: '短信模板：', value: '', have: true,
        options: list,
        change(value = this.value) {
          const _select = list.find(item => item.value === value);
          if (!_select) return;
          editList.find(item => item.key === 'notifyTemContent').value = _select.content;
        }
      },
      { type: 'textarea', key: 'notifyTemContent', label: '模板内容：', value: '', disabled: true, have: true, maxlength: 500, showWordLimit: true, notParams: true },
      { type: 'input', key: 'smsSign', label: '短信签名：', value: '', have: true, maxlength: 500, showWordLimit: true }
    ]
  }
  if (detail) {
    transformParams(editList, detail, isRed);
  }
  editList.forEach(item => {
    if (item.change && !item.hideItem) item.change();
  })
  return editList;
}
